package com.victor.gateway.handler;

import com.victor.common.core.constant.VersionConstant;
import com.victor.common.core.exception.CaptchaException;
import com.victor.common.core.web.domain.AjaxResult;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * 验证码获取
 *
 */
@Component
public class VersionHandler implements HandlerFunction<ServerResponse> {

    @Override
    public Mono<ServerResponse> handle(ServerRequest serverRequest)
    {
        AjaxResult ajax;
        try
        {
            ajax = new AjaxResult(200,"获取版本号成功！");
            ajax.put("version", VersionConstant.VERSION);

        }
        catch (CaptchaException e)
        {
            return Mono.error(e);
        }
        return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
    }
}

